
package com.mh.ObjectClasses;

import com.zx.ObjectClasses.Station;
import com.zx.ObjectClasses.TrainService;
import java.util.LinkedList;

public class Route implements Comparable {

    private boolean isBestRoute;
    private boolean isDirectTrain;
    private Station interchange;
    private Station startStation;
    private Station endStation;
    private TrainService startTrainService;
    private TrainService endTrainService;
    private LinkedList<Station> route;

    public Route(){
        isBestRoute = false;
        isDirectTrain = false;
        interchange = new Station();
        startStation = new Station();
        endStation = new Station();
        route = new LinkedList<Station>();
    }

    public Route(Station startStation){
        this.interchange = new Station();
        this.startStation = new Station();
        this.endStation = new Station();
        this.route = new LinkedList<Station>();

        this.startStation = startStation;
        this.route.add(startStation);
        this.isBestRoute = false;
        this.isDirectTrain = false;
    }

    public boolean isEmpty(){
        return (this.route.size() == 0);
    }

    public void setIsDirectTrainService(boolean b){
        isDirectTrain = b;
    }
    public boolean isDirectTrainService(){
        return isDirectTrain;
    }

    public void setInterchange(Station station){//for 1 transfer
        interchange = station;
    }
    public Station getInterchange(){
        return interchange;
    }

    public void setStartTrainService(TrainService ts){
        startTrainService = ts;
    }
    public TrainService getStartTrainService(){
        return startTrainService;
    }

    public void setEndTrainService(TrainService ts){
        endTrainService = ts;
    }
    public TrainService getEndTrainService(){
        return endTrainService;
    }


    public LinkedList<Station> getStations(){
        return route;
    }

    public void setBestRoute(boolean isBestRoute){
        this.isBestRoute = isBestRoute;
    }
    public boolean getIsBestRoute(){
        return isBestRoute;
    }

    public void addStation(Station station){
        route.add(station);
    }
    public Station getStation(int intStationNumber){
        return this.route.get(intStationNumber);
    }

    public void setStartStation(Station station){//add a new station to be the startStation
        startStation = station;
        this.route.addFirst(startStation);
    }
    public void changeStartStation(Station station){//replace the StartStation
        this.route.removeFirst();
        startStation = station;
        this.route.addFirst(startStation);
    }
    public Station getStartStation(){
        return this.route.getFirst();
    }

    public void setEndStation(Station station){
        endStation = station;
        this.route.addLast(endStation);
    }
    public Station getEndStation(){
        return this.route.getLast();
    }

    public void addStationIntoMiddle(int intStationNumber, Station station){
        this.route.add(intStationNumber, station);
    }

    public void remove(int i){
        this.route.remove(i);
    }

    public int getRouteSize(){
        return this.route.size();
    }

    public void clearRoute(){
        this.route.clear();
    }

    @Override
    public int compareTo(Object o) {
        if(getRouteSize() < ((Route)o).getRouteSize()){
            return 1;
        }else if(getRouteSize() == ((Route)o).getRouteSize()){
            return 0;
        }else{
            return -1;
        }
    }

}
